🎨 Retain register name - #2014
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe change preserves quantum-register names across QC and QCO allocation, conversion, and translation paths. Named allocations store ChangesQuantum register name propagation
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant SourceRegister
participant Translation
participant AllocationBuilder
participant Conversion
participant OpenQASM3
SourceRegister->>Translation: provide register name
Translation->>AllocationBuilder: allocate register with name
AllocationBuilder->>AllocationBuilder: validate uniqueness
AllocationBuilder-->>Translation: return allocation with name attribute
Conversion->>Conversion: copy name attribute
OpenQASM3->>Conversion: read stored register name
Conversion-->>OpenQASM3: emit named register
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
burgholzer
left a comment
There was a problem hiding this comment.
This looks like a great start.
Just a few quick side comments:
- does the OpenQASM importer already do this? Feels like it should also preserve the name.
- is this attribute retained across dialect conversions? Ideally, it would propagate through the QCO conversion and lead to a nice OpenQASM roundtrip. (Maybe this is already handled though)
- is there anything to do for QIR emission? (Both on classical and quantum registers)
- is there anything to do for the OpenQASM emission?
denialhaag
left a comment
There was a problem hiding this comment.
Thanks a lot for getting this started, @simon1hofmann! 🙂
Below, you can find two things that jumped out to me. In addition to that, I agree with @burgholzer's comment above. I would expect some changes in the OpenQASM translations and the QIR conversions to be necessary. 🤔
You're right, these should be added as well. Concerning QIR emission, |
I think you are right; register names only make sense for classical registers in the context of output recording. 🤔 |
yeah. for QIR emission, quantum registers do not really matter 👍🏼 |
|
@coderabbitai review |
❌ Action failedReview failed.
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@mlir/unittests/Dialect/QC/Translation/test_openqasm3_emission.cpp`:
- Around line 530-545: Extend ReusesQuantumRegisterNames with an invalid stored
register name, then require strict OpenQASM parsing of the emitted result.
Assert the output does not declare the invalid name while preserving the
existing valid-name assertion.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: ce584dc3-5254-4e6c-aed3-fda634cf5aca
📒 Files selected for processing (18)
CHANGELOG.mdmlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.hmlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.hmlir/include/mlir/Dialect/Utils/Utils.hmlir/lib/Conversion/QCOToQC/QCOToQC.cppmlir/lib/Conversion/QCToQCO/QCToQCO.cppmlir/lib/Dialect/QC/Builder/QCProgramBuilder.cppmlir/lib/Dialect/QC/Translation/OpenQASMToQCEmitter.cppmlir/lib/Dialect/QC/Translation/TranslateQCToOpenQASM3.cppmlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cppmlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cppmlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cppmlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cppmlir/unittests/Dialect/QC/IR/test_qc_ir.cppmlir/unittests/Dialect/QC/Translation/test_openqasm3_emission.cppmlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cppmlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cppmlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp
|
@coderabbitai review |
|
denialhaag
left a comment
There was a problem hiding this comment.
This looks really clean to me now! I have three more comments, but I'll already now to not blcok the PR further. I'll leave the final say to @burgholzer. 😌
Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Signed-off-by: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com>
…ntracked tensor initialization
…st for untracked tensor initialization" This reverts commit 4627ded.
# Conflicts: # CHANGELOG.md # mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp
burgholzer
left a comment
There was a problem hiding this comment.
This looks very clean now. I'll quickly push a PR resolving the conflicts, then tag this for auto-merge! 🥳
Signed-off-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
🤖 AI text below 🤖
Description
This PR retains source-level qubit-register names across the QC and QCO MLIR dialects. The builders attach non-empty names to the backing
memref.allocorqtensor.allocusing themqt.qubit_register_namestring attribute and reject duplicate non-empty names.The attribute is populated by the
QuantumComputationand typed OpenQASM translations, preserved by the QC-to-QCO and QCO-to-QC conversions, and reused for OpenQASM emission when it is a valid, unique OpenQASM identifier. Invalid or conflicting names fall back to generated identifiers. QIR emission remains unchanged because quantum-register names have no corresponding QIR runtime recording semantics.Codex materially assisted with implementation, tests, review preparation, conflict resolution, and validation. The human author remains responsible for the contribution.
Fixes #1616.
Checklist
If PR contains AI-assisted content:
🤖 *AI text below* 🤖(titles are exempt).